import * as echarts from 'echarts';
import {userstatistics,usertotals} from '@/api/user/statistics'
import { onBeforeMount,ref } from 'vue';
import type { string } from '_vue-types@3.0.2@vue-types';
let list=ref([])
export let articles=ref<any>([])

export let articless=ref<any>([])


const mz=function (data:any){
    let myChart =echarts.init( document.getElementById('qq') as HTMLElement,);
    // nickname.push(data)
    let nickname:string[]=[]
    let article_count:number[]=[]
    let fav_count:number[]=[]
    data.forEach((z:any) => {
        nickname.push(z.nickname)
        article_count.push(z.article_count)
        fav_count.push(z.fav_count)
    });
    articles.value = data.filter((v:any)=>{
       return v.article_count>=5
    })
    articless.value=data.filter((v:any)=>{
      return v.fav_count>=1
   })
    // data.forEach((v:any)=>{
    //   if(v.article_count>=4){
    //     articles.value=v.nickname
    //     Collections.value=v.article_count
    //   }
     
    // })
    // data.forEach((v:any)=>{
    //   if(v.fav_count>=6){
    //     articless.push(v.nickname)
    //     people.push(v.fav_count)
    //   }
     
    // })
    
    console.log(articles)

    console.log(articless)
    

    console.log(article_count)
    console.log(nickname,article_count,fav_count)
    console.log(data)
    console.log(myChart)
    const labelOption = {
  show: true,
  position:'center',
  distance: -30,
  align: 'center',
  verticalAlign: 'center',
  rotate: 90,
  formatter: '{c}  {name|{a}}',
  fontSize: 16,
  rich: {
    name: {}
  }
};
    let option;
            
// myChart.setOption({
//       series: [
//         {
//           label: labelOption
//         },
//         {
//           label: labelOption
//         },
       
//       ]
//     });
option = {
  xAxis: {
    type: 'category',
    data: nickname,
    axisLabel:{
        interval:0
      }
  },
  yAxis: {
    type: 'value'
  },
  toolbox: {
    show: true,
    orient: 'vertical',
    left: 'right',
    top: 'center',
    feature: {
      mark: { show: true },
      dataView: { show: true, readOnly: false },
      magicType: { show: true, type: ['line', 'bar', 'stack'] },
      restore: { show: true },
      saveAsImage: { show: true }
    }
  },
  
  legend: {
    data: ['文章数据', '收藏数据',]
  },
  series: [
    {
  
      data: article_count,
      type: 'bar',
      name: '文章数据',
      label: labelOption,
      emphasis: {
        focus: 'series'
      },
     
    //   axisLabel:{
    //     interval:-30
    //   }
     
    },
    {
        
  data: fav_count,
  type: 'bar',
  name: '收藏数据',
  label: labelOption,
  emphasis: {
    focus: 'series'
  },

//   axisLabel:{
//     interval:-30
//   }
 
}
  ]
};

option && myChart.setOption(option);
}
let listdx=ref([])
export function echartsmethods(){
    onBeforeMount(()=>{
        userstatistics().then((res)=>{
            console.log(res)
            list.value=res.data
            mz(res.data)
        })
    })
    usertotals().then((res:any)=>{
        console.log(res)
        listdx.value=res.count
    })
    return {
        listdx
    }
}